/**
 * Copyright &copy; 2012-2016 civet All rights reserved.
 */
package cn.mcsys.myadmin.modules.air.web;

import cn.mcsys.myadmin.common.config.Global;
import cn.mcsys.myadmin.common.persistence.Page;
import cn.mcsys.myadmin.common.web.BaseController;
import cn.mcsys.myadmin.common.web.JsonResult;
import cn.mcsys.myadmin.modules.air.entity.AirParkingLot;
import cn.mcsys.myadmin.modules.air.service.AirParkingLotService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 停车场管理Controller
 * @author leopold
 * @version 2018-08-13
 */
@Controller
@RequestMapping(value = "${adminPath}/air/airParkingLot")
public class AirParkingLotController extends BaseController {

	@Autowired
	private AirParkingLotService airParkingLotService;
	
	@RequiresPermissions("air:airParkingLot:view")
	@RequestMapping(value = {"list", ""})
	public String list(AirParkingLot airParkingLot, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AirParkingLot> page = airParkingLotService.findPage(new Page<AirParkingLot>(request, response), airParkingLot); 
		model.addAttribute("page", page);
		return "modules/air/airParkingLotList";
	}

	@RequiresPermissions("air:airParkingLot:view")
	@RequestMapping(value = "form")
	public String form(AirParkingLot airParkingLot, Model model) {
	    if (airParkingLot.getId() != null){
            airParkingLot = airParkingLotService.get(airParkingLot.getId());
        }
		model.addAttribute("airParkingLot", airParkingLot);
		return "modules/air/airParkingLotForm";
	}

	@RequiresPermissions("air:airParkingLot:edit")
	@RequestMapping(value = "save")
	public String save(AirParkingLot airParkingLot, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, airParkingLot)){
			return form(airParkingLot, model);
		}
		airParkingLotService.save(airParkingLot);
//		addMessage(redirectAttributes, "保存停车场成功");
		return "redirect:"+Global.getAdminPath()+"/air/airParkingLot/?repage";
	}
	
	@RequiresPermissions("air:airParkingLot:edit")
	@RequestMapping(value = "delete")
	public String delete(AirParkingLot airParkingLot, RedirectAttributes redirectAttributes) {
		airParkingLotService.delete(airParkingLot);
//		addMessage(redirectAttributes, "删除停车场成功");
		return "redirect:"+Global.getAdminPath()+"/air/airParkingLot/?repage";
	}

	@RequestMapping(value = "getById")
	@ResponseBody
	public JsonResult getById(Integer id) {
		return JsonResult.success(airParkingLotService.get(id));
	}

}